<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{.Title}}</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <script src="/statics/js/jquery.json.min.js"></script>
    <script src="/statics/layer/layer.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container-fluid  center-block" style="width: 450px;margin-top: 30px;margin-bottom: 30px">
    <form autocomplete="off">
        <div class="form-group">
            <div class="input-group">
                <span class="input-group-addon"  id="basic-addon">用户名称</span>
                <input type="text" class="form-control" autocomplete="off" {{if eq .Body.type 1}}value="{{.Body.data.UserName}}"{{end}} id="edit_name" name="edit_name" placeholder="输入用户名称">
            </div>
        </div>
        <div class="form-group">
            <div class="input-group">
                <span class="input-group-addon" id="basic-addon1">用户密码</span>
                <input type="text" class="form-control" autocomplete="off" {{if eq .Body.type 1}}value="{{.Body.data.Password}}"{{end}} id="edit_pwd" name="edit_pwd" placeholder="输入密码">
            </div>
        </div>

        <div class="checkbox center-block">
            <label class="text-danger">
                <input type="checkbox" name="permision"{{if eq .Body.type 1}}{{if  regexp .Body.data.Permissions "ADMIN"}}checked{{end}}{{end}}  value="ADMIN">超级管理
            </label>
            <label>
                <input type="checkbox" name="permision" {{if eq .Body.type 1}}{{if  regexp .Body.data.Permissions "MANAGER"}}checked{{end}}{{end}} value="MANAGER">任务管理
            </label>
            <label>
                <input type="checkbox" name="permision" {{if eq .Body.type 1}}{{if  regexp .Body.data.Permissions "ST"}}checked{{end}}{{end}} value="ST">任务起停
            </label>
            <label>
                <input type="checkbox" name="permision"{{if eq .Body.type 1}}{{if  regexp .Body.data.Permissions "LOGGER"}}checked{{end}}{{end}} value="LOGGER">日志管理
            </label>

        </div>
        <button type="button" style="width: 390px" class="btn btn-primary center-block" onclick="saveUser()">提交</button>
    </form>

</div>
</body>
<script type="application/javascript">
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.iframeAuto(index);
    function saveUser(){
        var username=$("#edit_name").val();
        var password=$("#edit_pwd").val();
        var permissions="";
        $("input[name='permision']:checked").each(function () {
            if(permissions==""){
                permissions+=this.value;
            }else{
                permissions+="|"+this.value;
            }
        });
        $.ajax({
            url: "/userInfo",
            data: $.toJSON({username:username,password:password,permissions:permissions}),
            type: 'POST',
            dataType: "JSON",
            success: function(data){
                parent.layer.msg(data.msg);
                if(data.code==0){
                    parent.layer.close(index)
                    parent.location.reload(true)
                }
            }
        })
    }

</script>
</html>